package io.xxx.xbutler.core.callback;

import com.alibaba.fastjson2.JSONObject;
import io.xxx.xbutler.domain.task.ReceiverType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 群内实时消息回调
 * <p>
 * 群内聊天消息通过“群内实时消息回调”发送给商家，聊天信息包含（群编号、发言用户编号、消息时间、消息内容），其中消息类型包含语音、文字、图片、链接。
 * 其中图片文件只会回调缩略图，原图片、视频、语音需要通过调用（机器人功能接口>机器人下载消息文件接口）进行下载，下载后会回调（5005）对应的文件给商家。
 * 当语音长度较短时，在消息回调中vcContent直接带了语音链接，无需再通过请求下载文件接口再进行下载，同时vcDownFileSerialNo也为空值；
 * 满足开群条件，企业微信外部群&普通群都支持该回调
 *
 * <pre>
 * {
 *     "nType": 5003,
 *     "vcMerchantNo": "",
 *     "vcRobotWxId": "",
 *     "vcRobotSerialNo": "",
 *     "vcSerialNo": "",
 *     "nResult": 1,
 *     "vcResult": "SUCCESS",
 *     "Data": {
 *         "vcMsgSerialNo": "",
 *         "vcMsgId": "",
 *         "vcChatRoomSerialNo": "",
 *         "vcChatRoomId": "",
 *         "vcFromWxUserSerialNo": "",
 *         "vcFromWxUserWxId": "",
 *         "vcToWxUserSerialNo": "",
 *         "vcToWxUserWxId": "",
 *         "nMsgType": 2001,
 *         "vcContent": "",
 *         "nVoiceTime": 0,
 *         "vcShareTitle": "",
 *         "vcShareDesc": "",
 *         "vcShareUrl": "",
 *         "dtMsgTime": "",
 *         "nIsHit": 1,
 *         "nPlatformMsgType": 10,
 *         "vcRelaSerialNo": "",
 *         "nMsgNum": -1,
 *         "vcDownFileSerialNo": "",
 *         "vcQuoteMsgId": "",
 *         "vcQuoteWxId": "wxid_vbhl78c0dq2822",
 *         "vcCardId": "",
 *         "vcContentXml": "",
 *         "reference_message_body": "{\"fromUser\":\"wxid_ql230wknc3a322\",\"atList\":\"<msgsource>\\n\\t<signature>V1_XEg6ZsCw|v1_XEg6ZsCw</signature>\\n\\t<tmp_node>\\n\\t\\t<publisher-id></publisher-id>\\n\\t</tmp_node>\\n</msgsource>\\n\",\"toUser\":\"wxid_792dumexyoh522\",\"msgContent\":\"绿叶精神又重现啦？\",\"msgtype\":1,\"msgSerId\":\"7931589934418104785\",\"msgSeq\":789785337,\"at\":\"<?xml version=\\\"1.0\\\"?>\\n<pushcontent content=\\\"奋斗大昌奋斗青春 : 绿叶精神又重现啦？\\\" nickname=\\\"奋斗大昌奋斗青春\\\" />\\n\",\"at_list\":\"<msgsource>\\n\\t<signature>V1_XEg6ZsCw|v1_XEg6ZsCw</signature>\\n\\t<tmp_node>\\n\\t\\t<publisher-id></publisher-id>\\n\\t</tmp_node>\\n</msgsource>\\n\"}",
 *         "nick_name": "" //发送者昵称
 * 		   "fileList": [
 *             {
 *                 "DownFileSerialNo": "202110281517473732101130371122002",
 *                 "FileType": 2,
 *                 "FileSize": 0
 *             }
 *         ]
 *     }
 * }
 * </pre>
 */
@Slf4j
@Component
public class _5003Handler extends RobotMessageHandler {

    @Override
    public String name() {
        return "群内实时消息回调";
    }

    @Override
    public boolean supports(int type) {
        return type == 5003;
    }

    @Override
    protected ReceiverType getReceiverType() {
        return ReceiverType.ROOM;
    }

    @Override
    protected String getReceiverId(JSONObject data) {
        return data.getString("vcChatRoomId");
    }

    @Override
    protected String getReceiverSerialNo(JSONObject data) {
        return data.getString("vcChatRoomSerialNo");
    }
}
